package dat255.calendarclock.model.event.interval;

import java.util.GregorianCalendar;

/**
 * The kind of interval that allows an event to happen once
 * @author Marcus Hultman
 */
public class OneTimeInterval extends Interval {

	/**
	 * needed to store in files with objectOutputStream;
	 */
	private static final long serialVersionUID = 7130869920268021914L;

	private GregorianCalendar date;
	
	public OneTimeInterval(GregorianCalendar date){
		this.date = date;
	}
	
	@Override
	public GregorianCalendar nextDateOfEvent(GregorianCalendar currentDate) {
		if (date.after(currentDate))
			return date;
		return null;
	}
	
	public GregorianCalendar getDate() {
		return this.date;
	}

	@Override
	public boolean equals(Interval interval) {
		if(interval instanceof OneTimeInterval) {
			return this.date.equals(((OneTimeInterval) interval).getDate());
		}
		else {
			return false;
		}
	}

}
